/*
 * Keypad.cpp
 *
 *  Created on: Dec 11, 2011
 *      Author: Michael Anderson
 *      Part of Team 955 Battery Cart project
 *      compiled on Eclipse with Arduino libraries and avr-gcc
 */

#include "MyKeypad.h"

byte rowPins[4] = { 28, 23, 24, 26 }; //These are hardcoded for now
byte colPins[3] = { 27, 29, 25 }; //Can be changed if we ever need multiple keypads (but why?)
Keypad mykeypad = Keypad(makeKeymap(KPAD_KEYS), rowPins, colPins, 4, 3);

MyKeypad::MyKeypad() {

}

uint8_t MyKeypad::getNum() {
    uint8_t k = mykeypad.getKey();

#if ENABLE_SERIAL_MENUS
    uint8_t s = Serial.read();

    if (s > 31 && s < 128)
        k = s;
#endif

    if (k == NO_KEY)
        return k;
    if (k < '0' || k > '9')
        return NO_KEY;
    return k - '0';
}

uint8_t MyKeypad::getKey() {
    uint8_t k = mykeypad.getKey();

#if ENABLE_SERIAL_MENUS
    uint8_t s = Serial.read();

    if (s > 31 && s < 128)
        return s;
#endif

    return k;
    return '$';
}
